import {http} from '@/utils/http/axios';

export interface BasicResponseModel<T = any> {
  code: number;
  message: string;
  data: T;
}

/**
 * @description: 获取用户权限
 */
export function getPermissions() {
  return http.request({
      url: '/permissions',
      method: 'get',
    },
    {
      isTransformResponse: false,
    });
}

/**
 * @description: 用户登录
 */
export function loginPasswd(params: any) {
  return http.request<BasicResponseModel>(
    {
      url: '/login/passwd',
      method: 'POST',
      params,
    },
    {
      isTransformResponse: false,
    }
  );
}

/**
 * @description: 发送验证码
 */
export function sendCode(params: any) {
  return http.request<BasicResponseModel>(
    {
      url: '/send_code',
      method: 'GET',
      params,
    },
    {
      isTransformResponse: false,
    }
  );
}

/**
 * @description: 用户登录
 */
export function loginSms(params: any) {
  return http.request<BasicResponseModel>(
    {
      url: '/login/sms',
      method: 'GET',
      params,
    },
    {
      isTransformResponse: false,
    }
  );
}

/**
 * @description: 用户修改密码
 */
export function changePassword(params: any, uid: any) {
  return http.request(
    {
      url: `/user/u${uid}/changepw`,
      method: 'POST',
      params,
    },
    {
      isTransformResponse: false,
    }
  );
}

/**
 * @description: 用户登出
 */
export function logout(params) {
  return http.request({
    url: '/login/logout',
    method: 'POST',
    params,
  });
}

/**
 * 获取用户列表
 * @param params
 */
export function getUserList(params?: any) {
  if (params) {
    params = {
      ...params,
      tag: import.meta.env.VITE_APP_DEFAULT_TAG,
    }
  }
  return http.request({
      url: '/user/list',
      method: 'POST',
      params,
    },
    {
      isTransformResponse: false,
    });
}

/**
 * 添加用户
 * @param params
 */
export function addUser(params?: any) {
  if (params) {
    params = {
      ...params,
      tag: import.meta.env.VITE_APP_DEFAULT_TAG,
    }
  }
  return http.request({
      url: '/user',
      method: 'PUT',
      params,
    },
    {
      isTransformResponse: false,
    });
}

/**
 * 编辑用户
 * @param params
 */
export function editUser(params?: any) {
  return http.request({
      url: '/user',
      method: 'POST',
      params,
    },
    {
      isTransformResponse: false,
    });
}

/**
 * 删除用户
 * @param id
 */
export function delUser(id: any) {
  return http.request({
      url: `/user/${id}`,
      method: 'DELETE',
    },
    {
      isTransformResponse: false,
    });
}
